<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="root"></div>

    <script src="https://unpkg.com/react@18/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>

    <script>
      // 1. 创建一个 root 容器
      const root = ReactDOM.createRoot(document.querySelector("#root"));

      // 2. 通过 React.createElement() 创建虚拟节点
      //        React.createElement(type, props, children)    === h(type, props, children)
      // const vnode = React.createElement("button", null, "按钮");
      // console.log("vnode", vnode);

      // <div id="box">
      //   <span>hello</span>
      //   <button onclick="alert()">点我</button>
      // </div>
      const vnode = React.createElement("div", { id: "box" }, [
        React.createElement("span", { key: "001" }, "hello"),
        React.createElement(
          "button",
          {
            key: "002",
            onClick: function () {
              alert("hello");
            },
          },
          "点我"
        ),
      ]);

      // 3. 调用容器的 render 方法渲染 虚拟DOM
      root.render(vnode);
    </script>
  </body>
</html>
